package buildcode;

import java.util.List;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import buildcode.build.BuildCommand;
import buildcode.build.BuildCommandBuilder;
import buildcode.database.DataBaseTable;
import buildcode.language.java.command.JavaEntityCommandExecute;
import buildcode.language.java.command.JavaXmlMapperCommandExecute;
import buildcode.support.ContextIdConstant;
import buildcode.util.DataBaseUtil;

public class EsmartBuild {

    @BeforeAll
    public static void testInit() {
        Context.setAuthor("wangzhiyue");
    }

    public static void main(String[] args) {
        List<DataBaseTable> res = DataBaseUtil.getTableInfo("jdbc:mysql://10.39.92.207/ecejservice?useUnicode=true&characterEncoding=UTF-8&useSSL=false", "dev_user", "123qweasd",
                "esmart_motor_driven_schedule_relation");

        String javaSrc = "D:\\git\\esmart-artificial-inteligence\\esmart-ai-service-api\\src\\main\\java";
        String xmlMapperSrc = "D:\\git\\esmart-artificial-inteligence\\esmart-ai-service\\src\\main\\resources";
        String tplDir = "esmart/";
        for (DataBaseTable base : res) {
            BuildCommand entity = BuildCommandBuilder.of(ContextIdConstant.CONTEXT_ID_ENTITY, tplDir + "Entity.vm").setExecute(new JavaEntityCommandExecute()).setPackageName("com.ecej.esmart.ai.po")
                    .setSrcLocation(javaSrc).setSuffix("Po").build();
            BuildCommand xmlMapper = BuildCommandBuilder.of(ContextIdConstant.CONTEXT_ID_XML_MAPPER, tplDir + "XmlMapper.vm").setExecute(new JavaXmlMapperCommandExecute()).setPackageName("mybatis")
                    .setSuffix("Mapper").setSrcLocation(xmlMapperSrc).setExportFileType("xml").build();
            entity.setNext(xmlMapper);
            entity.execute(base);
        }
    }

    @Test
    public void ecityeh() {
        List<DataBaseTable> res = DataBaseUtil.getTableInfo("jdbc:mysql://192.168.13.27/ecityeh?useUnicode=true&characterEncoding=UTF-8&useSSL=false", "ecpay", "8tsl8Gk#", "t_dictionary",
                "t_pay_priority_config_info");

        String javaSrc = "D:\\git\\ecej-payadmin\\ecej-payadmin-service-api\\src\\main\\java";
        String xmlMapperSrc = "D:\\git\\ecej-payadmin\\ecej-payadmin-service\\src\\main\\resources";
        String tplDir = "esmart/";
        for (DataBaseTable base : res) {
            base.setCamelCaseName(base.getCamelCaseName().substring(1));
            BuildCommand entity = BuildCommandBuilder.of(ContextIdConstant.CONTEXT_ID_ENTITY, tplDir + "Entity.vm").setExecute(new JavaEntityCommandExecute())
                    .setPackageName("com.ecej.payadmin.po.generated.ecityeh").setSrcLocation(javaSrc).setSuffix("Po").build();
            BuildCommand xmlMapper = BuildCommandBuilder.of(ContextIdConstant.CONTEXT_ID_XML_MAPPER, tplDir + "XmlMapper.vm").setExecute(new JavaXmlMapperCommandExecute())
                    .setPackageName("mybatis.ecityeh").setSuffix("Mapper").setSrcLocation(xmlMapperSrc).setExportFileType("xml").build();
            entity.setNext(xmlMapper);
            entity.execute(base);
        }
    }

    @Test
    public void communication() {
        List<DataBaseTable> res = DataBaseUtil.getTableInfo("jdbc:mysql://10.39.92.207/ecityeh?useUnicode=true&characterEncoding=UTF-8&useSSL=false", "dev_user", "123qweasd",
                "t_merc_info_channel_change_snapshot");

        String javaSrc = "D:\\git\\ecej-pay-communication\\ecej-pay-communication-api\\src\\main\\java";
        String xmlMapperSrc = "D:\\git\\ecej-pay-communication\\ecej-pay-communication-core\\src\\main\\java";
        String tplDir = "esmart/";
        for (DataBaseTable base : res) {
            base.setCamelCaseName(base.getCamelCaseName().substring(1));
            BuildCommand entity = BuildCommandBuilder.of(ContextIdConstant.CONTEXT_ID_ENTITY, tplDir + "Entity.vm").setExecute(new JavaEntityCommandExecute())
                    .setPackageName("com.ecej.payment.communication.model").setSrcLocation(javaSrc).setTpl(tplDir + "Entity.vm").setSuffix("").build();
            BuildCommand xmlMapper = BuildCommandBuilder.of(ContextIdConstant.CONTEXT_ID_XML_MAPPER, tplDir + "XmlMapper.vm").setExecute(new JavaXmlMapperCommandExecute())
                    .setPackageName("mybatis.ecityeh").setSuffix("Mapper").setSrcLocation(xmlMapperSrc).setExportFileType("xml").build();
            entity.setNext(xmlMapper);
            entity.execute(base);
        }
    }

    @Test
    public void stm() {
        List<DataBaseTable> res = DataBaseUtil.getTableInfo("jdbc:mysql://10.39.92.207/ecityeh?useUnicode=true&characterEncoding=UTF-8&useSSL=false", "dev_user", "123qweasd",
                "t_merc_info_channel_change_snapshot");

        String javaSrc = "D:\\git\\ecej-pay-account-stm\\account-stm-api\\src\\main\\java";
        String xmlMapperSrc = "D:\\git\\ecej-pay-account-stm\\account-stm-core\\src\\main\\resources";
        String tplDir = "esmart/";
        for (DataBaseTable base : res) {
            base.setCamelCaseName(base.getCamelCaseName().substring(1));
            BuildCommand entity = BuildCommandBuilder.of(ContextIdConstant.CONTEXT_ID_ENTITY, tplDir + "Entity.vm").setExecute(new JavaEntityCommandExecute())
                    .setPackageName("com.ecej.payment.stm.model").setSrcLocation(javaSrc).setSuffix("").build();
            BuildCommand xmlMapper = BuildCommandBuilder.of(ContextIdConstant.CONTEXT_ID_XML_MAPPER, tplDir + "XmlMapper.vm").setExecute(new JavaXmlMapperCommandExecute())
                    .setPackageName("mybatis.ecityeh").setSuffix("Mapper").setSrcLocation(xmlMapperSrc).setExportFileType("xml").build();
            entity.setNext(xmlMapper);
            entity.execute(base);
        }
    }

    @Test
    public void task() {
        List<DataBaseTable> res = DataBaseUtil.getTableInfo("jdbc:mysql://192.168.13.27/ecityeh?useUnicode=true&characterEncoding=UTF-8&useSSL=false", "ecpay", "8tsl8Gk#", "t_channel_fee_settle_info",
                "t_channel_fee_settle_difference_info");

        String javaSrc = "D:\\git\\ecej-pay-task\\src\\main\\java";
        String xmlMapperSrc = "D:\\git\\ecej-pay-task\\src\\main\\resources";
        String tplDir = "esmart/";
        for (DataBaseTable base : res) {
            base.setCamelCaseName(base.getCamelCaseName().substring(1));
            BuildCommand entity = BuildCommandBuilder.of(ContextIdConstant.CONTEXT_ID_ENTITY, tplDir + "Entity.vm").setExecute(new JavaEntityCommandExecute())
                    .setPackageName("com.ecej.pay.task.model.ecityeh").setSrcLocation(javaSrc).setSuffix("").build();
            BuildCommand dao = BuildCommandBuilder.of(ContextIdConstant.CONTEXT_ID_JAVA_MAPPER, tplDir + "Mapper.vm").setExecute(new JavaEntityCommandExecute())
                    .setPackageName("com.ecej.pay.task.dao.ecityeh").setSrcLocation(javaSrc).setSuffix("Dao").build();
            BuildCommand xmlMapper = BuildCommandBuilder.of(ContextIdConstant.CONTEXT_ID_XML_MAPPER, tplDir + "XmlMapper.vm").setExecute(new JavaXmlMapperCommandExecute())
                    .setPackageName("mybatis.ecityeh").setSuffix("Mapper").setSrcLocation(xmlMapperSrc).setExportFileType("xml").build();
            entity.setNext(dao).setNext(xmlMapper);
            entity.execute(base);
        }
    }
}
